package com.hfut.eeg.service;

import com.hfut.eeg.dao.SysInfoMapper;
import com.hfut.eeg.dto.SysInfoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 梁琦
 * @program: eeg
 * @Package com.hfut.eeg.service
 * @Description: TODO
 * @date 2019-11-05 16:30
 */
@Service
@Scope("singleton")
public class SysInfoService {

    @Autowired
    private SysInfoMapper sysInfo;

    /**
    * 获取当前系统信息
    */
    public HashMap getSysInfo(){
        HashMap<String,Object> map = new HashMap<>();
        SysInfoResult result = sysInfo.getSysInfo();
        //System.out.println(result);
        //未获取到数据
        if(result== null){
            return null;
        }

        map.put("history",result.getHistory());
        map.put("average",result.getAverage());
        map.put("abWaveNum",result.getAbWaveNum());
        map.put("savedTime",result.getSavedTime());

        HashMap<String,Integer>pie = new HashMap<>();
        pie.put("age1",result.getAge1());
        pie.put("age2",result.getAge2());
        pie.put("age3",result.getAge3());
        pie.put("age4",result.getAge4());

        map.put("pie",pie);
        return map;
    }

    public int updateSysAge(int age){
        return sysInfo.updateSysAge(age);
    }

    /**
    * 更新系统一冲波数量
    */
    public int updateSysAbWaveNum(int sum){
        return sysInfo.updateSysAbWaveNum(sum);
    }

    /**
    * 更新节省时间
    */
    public int updateSavedTime(int sum){
        return sysInfo.updateSavedTime(sum);
    }

    //缺少信息
    public int updateAverage(float sum){
        return sysInfo.updateAverage(sum);
    }
}
